package code;

public class Code_1750 {

    public static void main(String[] args){

        Code_1750 code_1750 = new Code_1750();
        String s = "bbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbccbcbcbccbbabbb";
        String s1 = "cabaabac";
        code_1750.minimumLength(s1);
    }
    public int minimumLength(String s) {
        if(s.isEmpty()){
            return 0;
        }

        int r = 0, l = s.length() - 1;
        boolean is = false;

        while(r < l){
            
            // 先从左边开始获取第一个
            char cR = s.charAt(r);
            // 判断右边 是否一样
            if(cR != s.charAt(l)){
                return l - r + 1;
            }

            // 左边进行寻找
            while(cR == s.charAt(r) && r < l){
                r++;
            }
            if(r == l){
                is = true;
            }

            // 右边进行寻找
            while(cR == s.charAt(l) && r < l){
                l--;
            }
        }
        if(r == l){
            if (is){
                return 0;
            }
            return 1;
        }

        return l - r + 1;
    }
}
